package disjunction.extensions.view
{
	/**
	 *
	 *
	 * @author Nick Wiggill
	 */
	
	public class DisplayObjectEntityRemover implements IEntityRemover
	{
		/** Removes an entity from the view. */
		public override function remove(entity:*):void
		{
			var entityView:EntityView = _entitiesByModel[entity];
			entityView.model = null;
			if (entityView != null)
			{				
				//remove from rendering system list (displayobjects)
				context.removeChild((entityView as DisplayObjectEntity2D).displayObject);	
				
				//remove from own lists (entities)
				_entities.splice(_entities.lastIndexOf(entityView), 1);
				delete _entitiesByModel[entity];
				
				//destroy the object
				if (entityDestroyer) //since this optional, check if it applies
				{		
					entityDestroyer.destroy(entity); //model? view? should be destroyFor()?
				}
			}
		}
	}
}